package com.heima.wemedia.controller;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.media.dtos.WmNewsDto;
import com.heima.model.media.dtos.WmNewsPageReqDto;
import com.heima.wemedia.entity.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 分页查询
     *
     * @param wmNewsPageReqDto
     * @return
     */
    @PostMapping("/page")
    public PageResult<WmNews> findByPage(@RequestBody WmNewsPageReqDto wmNewsPageReqDto) {
        return wmNewsService.findByPage(wmNewsPageReqDto);
    }

    /**
     * 保存、修改、发布自媒体文章
     *
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult saveNews(@RequestBody WmNewsDto wmNewsDto) {
        wmNewsService.saveNews(wmNewsDto);
        return ResponseResult.ok();
    }

    //自媒体文章上下架
    @PutMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        wmNewsService.downOrUp(dto);
        return ResponseResult.ok();
    }
}